package cn.doitedu.day02

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object T01_MapPartitionsWithIndexDemo {

  def main(args: Array[String]): Unit = {

    //1.创建SparkConf
    val conf = new SparkConf().setAppName("MapPartitionsWithIndexDemo")
      .setMaster("local[4]")

    //2.创建SparkContext
    val sc = new SparkContext(conf)

    val rdd1: RDD[Int] = sc.parallelize(List(1, 2, 3, 4, 5, 6, 8, 7, 9, 10))

    val rdd2: RDD[String] = rdd1.mapPartitionsWithIndex((index, it) => {
      it.map(e => s"partition: $index, ele: $e")
    })

    //rdd2.foreach(e => println(e))
    rdd2.saveAsTextFile("out/out09")
  }

}
